 package com.hospital.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.hospital.model.Cure;
import com.hospital.util.DbUtil;

public class CureDAO {
	//处方实现类
	public List<Cure> find(String name) {
		List<Cure> list = new ArrayList<Cure>();
		Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		//选择出挂号表中的以名字查找出处方表中的数据（既是他们以挂号的号码进行连接）
		String sql = "select * from t_cure where orderid in ( select oid from t_order where name = '" + name + "')";
		try {
			//运行sql语句
			conn = DbUtil.getConnection();
			stmt = conn.prepareStatement(sql);
			rs = stmt.executeQuery();
			while (rs.next()) {
				Cure cure = new Cure();
				cure.setId(rs.getInt(1));
				cure.setOid(rs.getString(2));
				cure.setCases(rs.getString(3));
				cure.setDrug(rs.getString(4));
				cure.setDrugmoney(rs.getDouble(5));
				cure.setItem(rs.getString(6));
				cure.setItemmoney(rs.getDouble(7));
				list.add(cure);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DbUtil.close(rs);
			DbUtil.close(stmt);
			DbUtil.close(conn);
		}
		return list;
	}
}